﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hotnet.Dal.BaseRepository;
using Hotnet.Entity;
using Hotnet.Entity.Enum;
using LinqExt;

namespace Hotnet.Dal.NSDalVideo
{
	public class DalVideoXTag : Repository<VideoXTag>
	{
		string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["HotnetConnectionString"].ConnectionString;
		public void Insert(List<VideoXTag> models)
		{
			using(HotnetDBDataContext ctx=new HotnetDBDataContext(connectionString))
			{
				ctx.GetTable<VideoXTag>().InsertAllOnSubmit(models);
				ctx.SubmitChanges();
			}
		}

		/// <summary>
		/// 返回VideoXTags列表
		/// </summary>
		/// <param name="id"></param>
		/// <param name="type"></param>
		/// <returns></returns>
		public VideoXTag[] ListVideoXTags(int id)
		{
			return ListBy(x => x.VideoID == id);
		}

		/// <summary>
		/// 返回tag 列表
		/// </summary>
		/// <param name="id"></param>
		/// <param name="type"></param>
		/// <returns></returns>
		public Tag[] ListVideoTags(int id)
		{
			var query = from videoTag in disableCacheDataContext.VideoXTag
						where videoTag.VideoID == id
						join tag in disableCacheDataContext.Tag on videoTag.TagID equals tag.TagID
						select tag;
			return query.ToArray();
		}


		public void Delete(int videoId)
		{
			DeleteBy(x => x.VideoID == videoId);
		}

	}
}
